Skip to main content

RouteProcessor

The RouteProcessor contract is used to perform complicated swaps that go through multiple pairs and AMMS.

The full contract can be found here.

Read-Only Functions

State-Changing Functions

processRoute

function processRoute(
address tokenIn,
uint256 amountIn,
address tokenOut,
uint256 amountOutMin,
address to,
bytes memory route
) external payable lock returns (uint256 amountOut);

Processes the off-chain generated route for token swap.

  • This function is payable and has a lock modifier to prevent re-entrancy attacks.
  • Executes a token swap along a specified route, with slippage protection through the amountOutMin parameter.

Parameters

NameTypeDescription
tokenInaddressThe address of the input token.
amountInuint256The amount of the input token to swap.
tokenOutaddressThe address of the output token.
amountOutMinuint256The minimum amount of the output token that must be received for the transaction not to revert.
toaddressThe address to send the output tokens to.
routebytesThe encoded data for the swap route, generated off-chain.

Returns

NameTypeDescription
amountOutuint256The actual amount of the output token received.

Reverts

  • This function reverts if the actual output amount is less than the minimum specified output amount.
  • This function reverts if there's a problem with executing the token swap along the route.

Events

This function does not emit any events.

Modifiers

modifier lock();

The lock modifier prevents re-entrancy attacks by ensuring that the function cannot be re-entered while it's being executed.

transferValueAndprocessRoute

function transferValueAndprocessRoute(
address payable transferValueTo,
uint256 amountValueTransfer,
address tokenIn,
uint256 amountIn,
address tokenOut,
uint256 amountOutMin,
address to,
bytes memory route
) external payable lock returns (uint256 amountOut);

Transfers some value to a specified address and then processes the off-chain generated route for token swap.

  • This function is payable and has a lock modifier to prevent re-entrancy attacks.
  • Executes a token swap along a specified route, with slippage protection through the amountOutMin parameter.

Parameters

NameTypeDescription
transferValueToaddressThe address to transfer the value to.
amountValueTransferuint256The amount of value to transfer.
tokenInaddressThe address of the input token.
amountInuint256The amount of the input token to swap.
tokenOutaddressThe address of the output token.
amountOutMinuint256The minimum amount of the output token that must be received for the transaction not to revert.
toaddressThe address to send the output tokens to.
routebytesThe encoded data for the swap route, generated off-chain.

Returns

NameTypeDescription
amountOutuint256The actual amount of the output token received.

Reverts

  • This function reverts if the actual output amount is less than the minimum specified output amount.
  • This function reverts if there's a problem with executing the token swap along the route.
  • This function reverts if the value transfer fails.

Events

This function does not emit any events.

Modifiers

modifier lock();

The lock modifier prevents re-entrancy attacks by ensuring that the function cannot be re-entered while it's being executed.